<template>
	<view class="mine">
		<scroll-view scroll-y="true" class="scrollView" @scrolltolower="loadMore">
			<view class="data-item" v-for="item,index in dataList" :key="index" @click="toDetail(item)">
				<view class="data-name">
					{{item.deviceName}}
				</view>
				<view class="data-info row-between">
					<!-- <rich-text class="text-content" :nodes="item.otherContent"></rich-text> -->
					<text class="text-content">{{item.createBy || 'XX'}}发布</text>
					<text>{{timestampToDate(item.createTime, 'ymdhm')}} 上传</text>
				</view>
				<scroll-view scroll-x class="row-center-random" style="width: 100%;"
					v-if="item.picture && item.picture != ''">
					<view class="data-img">
						<image v-for="(items,indexs) in item.picture.split(',')" :key="indexs" :src="baseUrl + items"
							mode="scaleToFill"></image>
					</view>
				</scroll-view>
			</view>
			<view class="list_loading" v-if="isAllData != 0">
				<view class="loading" v-if="isAllData == '1'">
					正在加载，请稍候
					<uni-icons type="spinner-cycle" size="16" style="margin-left: 4px;"></uni-icons>
				</view>
				<view class="all-data" v-else>已加载全部数据~</view>
			</view>
		</scroll-view>
		<you-bottom-btn  v-if="entInfo.maintainCompanyId !='null'" :btnConfig="bottomBtnConfig" @formSubmit="formSubmit">
		</you-bottom-btn>
	</view>
	</view>
</template>

<script>
	import Mine from "@/api/mine.js"
	import pageConfig from '@/config'
	const baseUrl = pageConfig.baseUrl
	import {
		timestampToDate
	} from '@/utils/index.js'
	export default {
		data() {
			return {
				baseUrl,
				bottomBtnConfig: [{
					text: '	新增',
					class: 'confirm',
					funcName: 'formSubmit'
				}],
				dataList: [],
				total: 0,
				pageInfo: {
					pageNum: 1,
					pageSize: 10
				},
				isAllData: '0',
				entInfo: {}
			}
		},
		onLoad(e) {
			this.entInfo = e;
			console.log(this.entInfo, 'this.entInfo ');
			this.getList()
		},
		onShow() {
			this.getList()
		},
		methods: {
			timestampToDate,
			formSubmit() {
				uni.navigateTo({
					url: '/subPages/mine/electricalSafety/addRecords?maintainCompanyId=' 
					+ this.entInfo.maintainCompanyId+'&entAuthId='+this.entInfo.entId+'&entName='+this.entInfo.entName
				})
			},
			toDetail(item) {
				uni.navigateTo({
					url: '/subPages/mine/electricalSafety/detail?id=' + item.id
				})
			},
			async getList() {
				this.isAllData == '1';
				let res = await Mine.getElecSafetyList(this.pageInfo);
				if(this.pageInfo.pageNum==1){
					this.dataList=res.rows
				}else{
					this.dataList.push(...res.rows);
				}
				console.log(this.dataList)
				this.total = res.total;
				let {
					pageNum,
					pageSize
				} = this.pageInfo;
				if (pageNum >= this.total / pageSize) {
					this.isAllData = '2';
				} else {
					this.isAllData == '0';
				}
			},
			loadMore() {
				let {
					pageNum,
					pageSize
				} = this.pageInfo;
				if (pageNum >= this.total / pageSize) {
					this.isAllData = '2';
					return;
				}
				this.$set(this.pageInfo, 'pageNum', pageNum + 1);
				this.getList();
			},
		}
	}
</script>

<style lang="scss" scoped>
	.mine {
		background: #F6F8FA;
		width: 100vw;
		height: 100vh;
		box-sizing: border-box;
		padding: 0 28rpx;
		background: #fff;
	}

	.scrollView {
		height: 100vh;
		box-sizing: border-box;
		padding-bottom: calc(env(safe-area-inset-bottom) + 64px);

		.data-item {
			margin-top: 20rpx;
			padding-bottom: 20rpx;
			border: 1px solid #fff;

			.data-name {
				font-size: 28rpx;
				color: $main-font-black;
				font-weight: bold;
			}

			.data-info {
				font-size: 24rpx;
				color: $main-font-auxiliary;
				margin-top: 10rpx;
			}

			.data-img {
				margin-top: 10rpx;

				image {
					height: 140rpx;
					width: 140rpx;
					margin-right: 20rpx;
					border-radius: 8rpx;
					background: #F6F8FA;
				}
			}
		}
	}
</style>